plug/socket: Warn if used outside X11
authorMatthias Clasen <mclasen@redhat.com>
Fri, 28 Aug 2015 16:48:02 +0000 (12:48 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 28 Aug 2015 16:48:02 +0000 (12:48 -0400)
Give a clear warning when either of these are realized on a non-X11
screen.

gtk/gtkplug.c
gtk/gtksocket.c

index 56c37f2367f7c0e2309ed15cb9f51e3dd0ba34ce..b65dacbef464bd3d5f42b7a452cc9e2ad33b5e61 100644 (file)
  *
  * The communication between a #GtkSocket and a #GtkPlug follows the
  * [XEmbed Protocol](http://www.freedesktop.org/Standards/xembed-spec).
- * This protocol has also been implemented in other toolkits,
- * e.g. Qt, allowing the same level of
- * integration when embedding a Qt widget
+ * This protocol has also been implemented in other toolkits, e.g. Qt,
+ * allowing the same level of integration when embedding a Qt widget
  * in GTK+ or vice versa.
  *
  * The #GtkPlug and #GtkSocket widgets are only available when GTK+
  * is compiled for the X11 platform and %GDK_WINDOWING_X11 is defined.
  * They can only be used on a #GdkX11Display. To use #GtkPlug and
- * #GtkSocket, you need to include the `gtk/gtkx.h`
- * header.
+ * #GtkSocket, you need to include the `gtk/gtkx.h` header.
  */
 
 struct _GtkPlugPrivate
@@ -1029,9 +1027,14 @@ gtk_plug_realize (GtkWidget *widget)
   const gchar *title;
   gchar *wmclass_name, *wmclass_class;
   gint attributes_mask;
+  GdkScreen *screen;
 
   gtk_widget_set_realized (widget, TRUE);
 
+  screen = gtk_widget_get_screen (widget);
+  if (!GDK_IS_X11_SCREEN (screen))
+    g_warning ("GtkPlug only works under X11");
+
   title = gtk_window_get_title (window);
   _gtk_window_get_wmclass (window, &wmclass_name, &wmclass_class);
   gtk_widget_get_allocation (widget, &allocation);
@@ -1064,7 +1067,7 @@ gtk_plug_realize (GtkWidget *widget)
       GdkWindow *root_window;
       attributes.window_type = GDK_WINDOW_TOPLEVEL;
 
-      root_window = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
+      root_window = gdk_screen_get_root_window (screen);
 
       gdk_error_trap_push ();
       if (priv->socket_window)
index 579a1f6c7b0dd810b37c8a251d00e134c7caa4b2..6213cebe422893d169c61a3655727d11c0f58291 100644 (file)
  *
  * The communication between a #GtkSocket and a #GtkPlug follows the
  * [XEmbed Protocol](http://www.freedesktop.org/Standards/xembed-spec).
- * This protocol has also been implemented in other toolkits,
- * e.g. Qt, allowing the same level of
- * integration when embedding a Qt widget
+ * This protocol has also been implemented in other toolkits, e.g. Qt,
+ * allowing the same level of integration when embedding a Qt widget
  * in GTK or vice versa.
  *
  * The #GtkPlug and #GtkSocket widgets are only available when GTK+
  * is compiled for the X11 platform and %GDK_WINDOWING_X11 is defined.
  * They can only be used on a #GdkX11Display. To use #GtkPlug and
- * #GtkSocket, you need to include the `gtk/gtkx.h`
- * header.
+ * #GtkSocket, you need to include the `gtk/gtkx.h` header.
  */
 
 /* Forward declararations */
@@ -391,9 +389,14 @@ gtk_socket_realize (GtkWidget *widget)
   GdkWindowAttr attributes;
   XWindowAttributes xattrs;
   gint attributes_mask;
+  GdkScreen *screen;
 
   gtk_widget_set_realized (widget, TRUE);
 
+  screen = gtk_widget_get_screen (widget);
+  if (!GDK_IS_X11_SCREEN (screen))
+    g_warning ("GtkSocket: only works under X11");
+
   gtk_widget_get_allocation (widget, &allocation);
 
   attributes.window_type = GDK_WINDOW_CHILD;